package io.renren.modules.shop.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.modules.shop.entity.ProductDetailEntity;
import io.renren.modules.shop.entity.ProductDetailRackEntity;
import io.renren.modules.shop.entity.ProductEntity;
import io.renren.modules.shop.service.ProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.shop.entity.MerchantEntity;
import io.renren.modules.shop.service.MerchantService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author Yangqianyong
 * @email sunlightcs@gmail.com
 * @date 2021-11-17 15:35:51
 */
@RestController
@RequestMapping("shop/merchant")
public class MerchantController {
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private ProductService productService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("shop:merchant:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = merchantService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{merchantId}")
//    @RequiresPermissions("shop:merchant:info")
    public R info(@PathVariable("merchantId") Long merchantId){
		MerchantEntity merchant = merchantService.getById(merchantId);

        return R.ok().put("merchant", merchant);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("shop:merchant:save")
    public R save(@RequestBody MerchantEntity merchant){
		merchantService.save(merchant);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("shop:merchant:update")
    public R update(@RequestBody MerchantEntity merchant){
		merchantService.updateById(merchant);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("shop:merchant:delete")
    public R delete(@RequestBody Long[] merchantIds){
		merchantService.removeByIds(Arrays.asList(merchantIds));

        return R.ok();
    }

    @RequestMapping("/products")
    public R getMerchant(@RequestParam Long id){
        List<ProductDetailRackEntity> list = productService.getMerchant(id);

        return R.ok().put("list",list);
    }

    @RequestMapping("/productRacks")
    public R getMerchant(@RequestParam Long mid,@RequestParam Integer rack){
        List<ProductDetailRackEntity> list = productService.getMerchant(mid,rack);

        return R.ok().put("list",list);
    }

}
